package com.aaa.springboot_rbac.service.impl;

import com.aaa.springboot_rbac.dao.EmpDao;
import com.aaa.springboot_rbac.entity.Dept;
import com.aaa.springboot_rbac.entity.Emp;
import com.aaa.springboot_rbac.service.EmpService;
import com.aaa.springboot_rbac.util.CustomException;
import com.aaa.springboot_rbac.util.Page;
import com.aaa.springboot_rbac.util.ResultStatus;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @FileName: EmpServiceImpl
 * @Description:
 * @Author: 张钰哲
 * @CreateTime: 2025/8/27 15:51
 * @Version: 1.0.0
 */
@Service
public class EmpServiceImpl implements EmpService {
    @Resource
    private EmpDao empDao;
    @Override
    public Emp queryByEmpNo(Integer empNo) {
        return empDao.queryByEmpNo(empNo);
    }

    @Override
    public int add(Emp emp) {
        return empDao.add(emp);
    }

    @Override
    public int update(Emp emp) {
        return empDao.update(emp);
    }

    @Override
    public int deleteByNo(Integer empNo) {
        return empDao.deleteByNo(empNo);
    }

    @Override
    public PageInfo queryByPage(Page<Emp> page) {
        Integer pageNo = page.getPageNo();
        Integer pageSize = page.getPageSize();
        if (pageNo == null || pageSize == null ||  pageNo <= 0 || pageSize <= 0) {
            throw new CustomException(ResultStatus.PARAM_ISNULL.getStatusCode(), ResultStatus.PARAM_ISNULL.getStatusMsg());
        }
        PageHelper.startPage(pageNo,pageSize);
        Emp data = page.getData();
        List<Emp> deptList = empDao.queryByParam(data);
        return new PageInfo(deptList);
    }
}
